﻿using System;
using System.Collections.Generic;
using System.Net;
using System.Text;

namespace SharpSoft.Net.P2P.NatModels
{
    public struct IpInfo
    {
        public IpInfo(string address,int port)
        {
            Address = address;
            Port = port;
        }
        public IpInfo(IPEndPoint endPoint)
        {
            Address = endPoint.Address.ToString();
            Port = endPoint.Port;
        }
        public string Address { get; set; }

        public int Port { get; set; }

        public IPEndPoint ToIPEndPoint()
        {
            return new IPEndPoint(IPAddress.Parse(Address), Port);
        }

        public override bool Equals(object obj)
        {
            if (obj is IpInfo ii)
            {
                return ii.Address == this.Address && ii.Port == this.Port;
            }
            return false;
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

        public override string ToString()
        {
            return $"{Address}:{Port}";
        }
    }
}
